<?php
include_once 'common.php';

if(isset($_GET['website']) && !empty($_GET['website']))
{
	// get webshop id...
	$query = "	SELECT 
					* 
				FROM Webshops 
				WHERE URL = '".str_replace("'","",$_GET['website'])."'
					AND CustomerID = '".str_replace("'","",$_SESSION['login']['ID'])."'";
	
	$result = $_MySQL->runQuery($query);
	if(mysql_num_rows($result) > 0)
	{
		$row = mysql_fetch_assoc($result);
		if($row['Metatag'] == '')
		{
			$newMETA = generateWebshopActivatiecode();
			$query = "	UPDATE Webshops SET
							Metatag = '".str_replace("'","",$newMETA)."'
						WHERE ID = '".str_replace("'","",$row['ID'])."'";
			$_MySQL->runQuery($query);
		}
		else
		{
			$newMETA = $row['Metatag'];
		}
		
		$filename = $newMETA.'.html';
		
		$fileContents = "<html>\n";
			$fileContents .= "<head>\n";
				$fileContents .= "<title>Prijsgezocht HTML file</title>\n";
				$fileContents .= "<meta name=\"prijsgezocht\" value=\"".$newMETA."\" />\n";
			$fileContents .= "</head>\n";
		$fileContents .= "<body>\n";
		$fileContents .= "nothing to show here...<br /><br />so, you best be gone now\n";
		$fileContents .= "</body>\n"; 
		$fileContents .= "</html>\n"; 
		
		// force download
		header("Pragma: public"); // required
        header("Expires: 0");
        header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
        header("Cache-Control: private",false); // required for certain browsers
        header("Content-Transfer-Encoding: binary");
        header("Content-Disposition: attachment; filename=\"" . $filename . "\";" );
        
		echo $fileContents;
	}
	else 
	{
		include_once 'header.php';
		?>
		<b>ERROR</b>:<br />
		Onbekende website
		<?php	
		include_once 'footer.php';
	}
}
else 
{
	include_once 'header.php';
	?>
	<b>ERROR</b>:<br />
	Onbekende website
	<?php	
	include_once 'footer.php';
}